<!-- 社群营销 搜索 -->
<template>
  <div id="communityMarketSearch">
    <van-sticky>
      <div class="Search flex-a-c">
        <div class="address " @click="onChangeCity">{{address}}<i class="iconfont icon-icon_more11"></i></div>
        <van-search v-model="kwd" placeholder="搜索门店" shape='round' @search="onSearch"/>
      </div>
    </van-sticky>

    <div class="list">
      <div class="item flex-a-c" :class="[activeid == item.id? 'active-select':'']"  v-for="(item,index) in list" :key="item.id" @click="onClickStore(item)">
        <div class="item-left">
          <div class="size-16" style="">
            <div class="tag" v-show="activeid == item.id" style="margin: 0;">当前门店</div> <div class="tag" v-show="index == 0">距离最近</div>{{item.store_name}}
          </div>
          <div class="size-12" style="color:#6E6E79;margin-top:0.5rem;font-weight: 400;"><i class="iconfont icon-zx_map_locate1"></i>{{item.distance}}{{item.unit}}</div>
        </div>
        <div class="item-right">
          加入
        </div>

        <div class="triangle" v-if="activeid == item.id">
          <i class="iconfont icon-icon_select1"></i>
        </div>
      </div>

      <div v-show="list.length == 0 && !this.$store.state.isloadding" style="margin-top: 2rem;"> 该地区暂无门店数据，请切换地址...</div>
    </div>

    <yd-cityselect v-model="addressShow" :callback="addressCallback" :items="district"></yd-cityselect>
  </div>
</template>

<script>
export default {
  data () {
    return {
      activeid: 0,
      kwd: '',
      point: {},
      list: [],
      current_page: 1,
      last_page: 1,
      isLoadMore: true,

      addressShow: false,
      address: '',
      district: district
    };
  },

  created() {
    this.activeid = this.$route.query.storeid;
    this.initData();
    this.fun.getLocation('正在定位中')
      .then((res)=> {
        console.log(res)
        this.point = res.point;
        this.address = res.addressComponent.city ;
        this.getData();
      })
      .catch((err)=> {
        console.log(err);
      });
  },

  components: {},

  computed: {},

  mounted() {},

  methods: {
    async getData() {
      let { result, msg, data } = await $http.get("plugin.community-marketing.frontend.controllers.index.changeStore",{
        name: this.kwd,
        lng: this.point.lng,
        lat: this.point.lat,
        page: this.current_page,
        city_name: this.address
      },".");
      if (result == 0) return this.$toast(msg);
      if (this.current_page == 1) {
        this.list = data.list.data || [];
      } else if (this.current_page > 1) {
        this.list = this.list.concat(data.list.data || []);
      }
      this.current_page = data.list.current_page;
      this.last_page = data.list.last_page;
      this.isLoadMore = true;
    },
    getMoreData() {
      if (this.current_page >= this.last_page) {
        return;
      }
      this.isLoadMore = false;
      this.current_page += 1;
      this.getData();
    },
    onSearch(){
      this.initData();
      this.getData();
    },
    initData(){
      this.current_page = 1;
      this.isLoadMore = true;
      this.last_page = 1;
      this.list = [];
    },
    onClickStore(e){
      this.$router.push(this.fun.getUrl("communityMarketIndex",{}, {mode: 'qrStore',store_id: e.id,is_alone: 0,chg: 1}));
    },
    onChangeCity(){
      this.addressShow = true;
    },
    // 地址回调
    addressCallback(obj) {
      // this.address = obj.itemName1 + " " + obj.itemName2 + " " + obj.itemName3;
      this.address = obj.itemName2;
      this.initData();
      this.getData();
    },
  }
};

</script>
<style lang='scss' rel='stylesheet/scss' scoped>
#communityMarketSearch{
  .size-14 {
    font-size: .875rem;
    line-height: .875rem;
  }
  .size-16 {
    font-size: 1rem;
    line-height: 1.25rem;
  }
  .size-12 {
    font-size: .75rem;
    line-height: .75rem;
  }
  .size-11 {
    font-size: 0.6875rem;
    line-height: .6875rem;
  }
  .Search{
    height: 2.75rem;
    background: #fff;
    padding: 0 0.875rem;
    .address{
      width: 40%;
      text-align: left;
    }
    .van-search{
      flex: 1;
      padding: 0;
    }
  }
  .list{
    padding: 0.875rem;
    .item{
      background: #fff;
      margin-bottom: 0.75rem;
      border-radius: .5rem;
      padding: 0.875rem 1rem;
      border: 1px solid #fff;
      font-weight: bold;
      position: relative;
      overflow: hidden;
      .item-left{
        text-align: left;
        flex: 1;

        .tag{
          display: inline-block;
          border: 1px solid #F15353;
          color: #F15353;
          border-radius: 4px;
          line-height: 1rem;
          padding: 0 4px;
          font-size: 0.75rem;
          margin-right: 0.5rem;
          font-weight: 400;
          vertical-align: top;
        }
      }
      .iconfont{
        font-size: 0.75rem;
        margin-right: 0.25rem;
      }
      .item-right{
        padding-left: 1rem;
        line-height: 2rem;
        border-left: 1px solid #D6D6DC;
      }
    }
    .active-select{
      border: 1px solid #F15353;
    }
    .triangle {
      position: absolute;
      right: -1px;
      bottom: 0;
      width: 0;
      height: 0;
      border-color: #F15353 transparent; /*上下颜色 左右颜色*/
      border-width: 0 0 24px 30px;
      border-style: solid;
      i {
        position: absolute;
        bottom: -24px;
        right: 0;
        font-weight: bold;
        color: #fff;
      }
    }
  }
}
</style>